package com.baseDemo.web.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baseDemo.web.entity.CatalogEntity;
import com.baseDemo.web.service.catalog.CatalogService;

@Controller
@RequestMapping(value = "/catalog", produces = "application/json;charset=UTF-8")
public class CatalogController {
	@Resource
	CatalogService catalogService;
	@RequestMapping("/getCatalog")
	public @ResponseBody List<CatalogEntity> getCatalog(HttpServletRequest request,
			@RequestParam("node") String node) {
		return catalogService.getChildren(node, request);
	}
	@RequestMapping("/updateCatalogText")
	public @ResponseBody String updateCatalogText(@RequestBody CatalogEntity catalogEntity){
		return catalogService.updateCatalogText(catalogEntity);
	}
	@RequestMapping("/addCatalogText")
	public @ResponseBody String addCatalogText(@RequestBody CatalogEntity catalogEntity){
		return catalogService.addCatalog(catalogEntity);
	}
	@RequestMapping("/updateCatalogParent")
	public @ResponseBody String updateCatalogParent(@RequestParam String id,@RequestParam String newParent){
		return catalogService.updateCatalogParent(id, newParent);
	}
	@RequestMapping("/destroyCatalog")
	public @ResponseBody String destroyCatalog(@RequestBody CatalogEntity catalogEntity){
		return catalogService.deleteCatalog(catalogEntity);
	}
}
